<template>
  <div class="cart-add-container">
    <div class="cart-login-wrap" v-if="hasnotlogin">
      登录后可同步账户购物车中的商品
      <div class="cart-login" @click="cartlogin">登录</div>
    </div>
    <div class="cart-add-content">
      <div class="content-top">
        <div class="position">
          <img src="images/position.png" alt />
          <span>苏州园区腾飞塔楼A1幢二楼</span>
        </div>
        <div class="edit" @click="editcart">编辑商品</div>
      </div>
      <div class="content-bottom" v-for="(item,index) in showcartlist" :key="index">
        <div class="head-wrap">
          <div class="img1-wrap">
            <img
              :src="item.choosed?'images/selected.png':'images/no-select.png'"
              alt
              class="img1"
              @click="clickshopitem(index)"
            />
          </div>
          <i class="img2"></i>
          <span>{{item.shopname}}</span>
        </div>
        <div class="content-wrap">
          <div class="content-wrap-top">
            <span class="type">跨自营/店铺满减</span>
            <p class="type-des">购满199元，可减30元，还差110元</p>
            <span class="add-item">去凑单</span>
          </div>
          <div class="content-wrap-bottom" v-for="(result,i) in item.list" :key="i">
            <i>
              <img
                :src="result.selected?'images/selected.png':'images/no-select.png'"
                class="bottom-img1"
                @click="clickgooditem(index,i)"
              />
            </i>

            <img :src="result.url" alt class="bottom-img2" />
            <div class="goods-content">
              <div class="pro-name">{{result.desc}}</div>
              <div class="pro-type">{{result.type}}</div>
              <div class="pro-price">
                <p class="price">
                  <span>
                    ￥
                    <em>{{result.price}}</em>
                  </span>
                </p>
                <div class="plus-minus">
                  <div class="minus" @click="minus(index,i)">-</div>
                  <div class="count">
                    <input
                      class="num"
                      type="tel"
                      :value="result.count"
                      max="200"
                      prevalue="1"
                      lowestbuy="0"
                    />
                  </div>
                  <div class="plus" @click="plus(index,i)">+</div>
                </div>
              </div>
              <div class="pro-action">
                <div class="m-action">
                  <span class="span6">移入关注</span>
                  <span @click="del(index,i)">删除</span>
                </div>
              </div>
            </div>
            <div class="additional">
              <div class="additional-inner">
                <span class="cuxiao">促销</span>
                <div class="choosable">
                  <p>满199元减30元，满399元减60元，满799元减120元</p>
                  <span>4个可选</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="cart-add-foot">
      <i class="foot-select">
        全选
        <img
          :src="istotalClick?'images/selected.png':'images/no-select.png'"
          class="foot-img"
          @click="totalselect"
        />
      </i>
      <div class="total">
        <div class="total-detail">
          <p>
            总计
            <span>￥{{totalcost}}元</span>
          </p>
        </div>
        <div class="tobuy" :class="{pretopay:atleastonegood==true}" @click="tobuy">
          去结算
          <span>（{{goodnumber}}件）</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import store from "../../store/index.js";
export default {
  name: "cartaddpro",
  store,
  computed: {
    FloorCardList() {
      return this.$store.state.FloorCardList;
    },
    showcartlist() {
      return this.$store.state.showcartlist;
    },
    istotalClick() {
      return this.$store.state.istotalClick;
    },
    // isshopClick(){
    //   return this.$store.state.isshopClick;
    // },
    totalcost() {
      return this.$store.state.totalcost;
    },
    atleastonegood() {
      return this.$store.state.atleastonegood;
    },
    goodnumber() {
      return this.$store.state.goodnumber;
    },
    hasnotlogin() {
      return this.$store.state.hasnotlogin;
    }
  },
  data() {
    return {};
  },
  methods: {
    cartlogin() {
      this.$router.push("/login");
    },
    plus(index, i) {
      this.showcartlist[index].list[i].count++;
      this.$store.commit("calculate");
    },
    minus(index, i) {
      if (this.showcartlist[index].list[i].count > 1) {
        this.showcartlist[index].list[i].count--;
        this.$store.commit("calculate");
      }
    },
    del(index, i) {
      if (this.showcartlist[index].list.length == 1) {
        this.showcartlist.splice(index, 1);
      } else {
        this.showcartlist[index].list.splice(i, 1);
      }
      if (this.showcartlist.length == 0) {
        this.$store.commit("empty");
      }
      this.$store.commit("calculate");
    },
    totalselect() {
      // this.isClick = !this.isClick;
      this.$store.commit("totalselect");
      this.$store.commit("calculate");
    },
    clickgooditem(index, i) {
      this.showcartlist[index].list[i].selected = !this.showcartlist[index]
        .list[i].selected;
      this.$store.commit("goodselect", index);
      this.$store.commit("calculate");
    },
    clickshopitem(index) {
      this.showcartlist[index].choosed = !this.showcartlist[index].choosed;
      this.$store.commit("shopselect", index);
      this.$store.commit("calculate");
    },
    tobuy() {
      this.$router.push("/login");
    },
    editcart() {
      this.$store.commit("editcart");
      this.$store.commit("calculate");
    }
  }
};
</script>

<style scoped>
.pretopay {
  background: #e93b3d !important;
}
.cart-login-wrap {
  text-align: center;
  height: 60px;
  line-height: 60px;
  font-size: 14px;
  color: #333;
  background-color: #fff;
}

.cart-login {
  display: inline-block;
  margin-left: 10px;
  padding: 0 21px;
  height: 30px;
  border-radius: 4px;
  line-height: 30px;
  text-align: center;
  color: #fff;
  background-color: #e93b3d;
}

.content-top {
  overflow: hidden;
  position: relative;
  padding: 0 10px;
  height: 45px;
  margin-bottom: -1px;
  line-height: 45px;
  background: #fff;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.position {
  color: #999;
  max-width: 30%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.position img {
  display: inline-block;
  vertical-align: middle;
  width: 13px;
  height: 15px;
  margin: -2px 5px 0 0;
  /* background-size: 13px !important; */
}

.position span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit {
  padding-left: 10px;
  font-size: 14px;
  color: #e93b3d;
}

.content-bottom {
  position: relative;
  margin-bottom: 15px;
  background: #fff;
  overflow: hidden;
}

.head-wrap {
  box-sizing: border-box;
  position: relative;
  display: flex;
  align-items: center;
  padding: 5px 10px 5px 42px;
  min-height: 40px;
  z-index: 1;
  border-top: #e5e5e5 1px solid;
  border-bottom: #e5e5e5 1px solid;
}

.img1-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 42px;
  height: 100%;
}

.img1 {
  position: absolute;
  left: 50%;
  top: 28%;
  display: block;
  width: 20px;
  height: 20px;
  margin-left: -10px;
}

.img2 {
  background-image: url(//wq.360buyimg.com/fd/h5/wxsq_dev/shopcart/images/sprite@2x_3f74538e.png);
  background-position: 0 0;
  background-size: 64px 42px;
  background-repeat: no-repeat;
  width: 20px;
  height: 20px;
  margin-right: 5px;
}

.head-wrap span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 700;
  margin-right: 10px;
  width: 100%;
}

.content-wrap-top {
  padding-left: 10px;
  opacity: 0.99;
  min-height: 30px;
  padding-top: 10px;
  padding-bottom: 0;
}

.type {
  margin-left: 10px;
  background-color: #e93b3d;
  text-align: center;
  border-radius: 3px;
  position: relative;
  display: inline-block;
  background: #e93b3d;
  color: #fff;
  font-size: 10px;
  padding: 0 5px;
  height: 15px;
  line-height: 15px;
  margin: 2px 5px 0 0;
  vertical-align: top;
}

.type-des {
  padding-right: 20px;
  line-height: 1.45;
  font-size: 12px;
  color: #333;
  font-weight: 400;
  flex: 1;
  box-sizing: border-box;
  display: inline-block;
  margin-right: 10px;
  width: 196px;
}

.add-item {
  padding-right: 5px;
  font-size: 12px;
  color: #999;
}

.content-wrap-bottom {
  z-index: 1;
  position: relative;
  min-height: 75px;
  padding: 5px 0 15px 128px;
  background: #fff;
}

.content-wrap-bottom i {
  left: 0;
  width: 63px;
  height: 100%;
  z-index: 1;
  display: block;
  position: absolute;
  top: 0;
}

.bottom-img1 {
  top: 35px;
  left: 21px;
  background-color: #fff;
  position: absolute;
  display: block;
  width: 20px;
  height: 20px;
  margin-left: -10px;
}

.bottom-img2 {
  position: absolute;
  left: 43px;
  top: 5px;
  display: block;
  width: 75px;
  height: 75px;
  border: 0 none;
  vertical-align: top;
}

.goods-content {
  min-height: 75px;
}

.pro-name {
  font-size: 14px;
  padding-right: 10px;
  margin-bottom: 5px;
  word-break: break-all;
  position: relative;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.pro-type {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
  background-color: #fff;
  font-size: 14px;
  color: #666;
  margin: 8px 10px 10px 0;
  padding: 1px 25px 1px 5px;
  border: 1px solid #e5e5e5;
  border-radius: 2px;
}

.pro-price {
  position: relative;
  display: flex;
  align-items: center;
  margin: 5px 10px 0 0;
  justify-content: space-between;
}

.price {
  flex: 1;
  line-height: 16px;
  color: #e93b3d;
  font-size: 10px;
}

.price em {
  font-size: 16px;
}

.plus-minus {
  position: relative;
  display: flex;
  width: 107px;
  border-radius: 4px;
  overflow: hidden;
  background-color: #f7f7f7;
  flex-direction: row;
  align-items: center;
}

.minus {
  width: 30px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  background: hsla(0, 0%, 80%, 0.3);
}

.count {
  position: relative;
  border-left: 1px solid #fff;
  border-right: 1px solid #fff;
}

.count input {
  height: 30px;
  line-height: 30px;
  width: 45px;
  text-align: center;
  outline: none;
  border: 0;
}

.plus {
  position: relative;
  width: 30px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  background: hsla(0, 0%, 80%, 0.3);
}

.pro-action {
  position: relative;
  margin: 5px 10px 5px 0;
  height: 12px;
}

.m-action {
  margin-right: -10px;
  color: #999;
  font-size: 0;
  font-family: Helvetica;
  text-align: right;
}

.m-action span {
  position: relative;
  padding: 0 10px;
  line-height: 12px;
  font-size: 12px;
}

/* .span6 {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
  background-color: #e5e5e5;
  width: 1px;
  right: 0;
  top: 2px;
  bottom: 2px;
} */

.additional {
  margin: 5px 0 0 -126px;
  position: relative;
  padding: 0 10px 0 42px;
}

.additional-inner {
  position: relative;
  padding: 3px 0 6px;
  background-color: #fef5f5;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.cuxiao {
  margin: 1px 10px 0;
  color: #666;
  line-height: 1.4em;
  font-size: 12px;
  flex-shrink: 0;
}

.choosable {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
}

.choosable p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 10px;
  font-size: 12px;
  flex: 1;
  color: #999;
}

.choosable span {
  font-family: arial;
  font-size: 12px;
  color: #999;
}

.cart-add-foot {
  left: 0;
  right: 0;
  margin: 0 auto;
  height: 50px;
  width: 100%;
  background: hsla(0, 0%, 100%, 1);
  color: #333;
  font-size: 14px;
  position: fixed;
  z-index: 99;
  bottom: 0;
}

.foot-select {
  width: 40px;
  padding-top: 32px;
  font-size: 10px;
  text-align: center;
  height: 15px;
  color: #999;
  z-index: 1;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

.foot-img {
  position: absolute;
  left: 50%;
  top: 28%;
  display: block;
  width: 20px;
  height: 20px;
  margin-left: -10px;
}

.total {
  position: absolute;
  top: 0;
  right: 0;
}

.total-detail {
  display: flex;
  -webkit-box-orient: vertical;
  flex-direction: column;
  -webkit-box-pack: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1em;
  height: 50px;
  text-align: right;
  float: left;
  font-size: 16px;
  position: relative;
}

.total-detail span {
  color: #e93b3d;
  font-family: arial;
}

.tobuy {
  background: #d7d7d7;
  color: #fff;
  float: right;
  display: block;
  width: 110px;
  height: 50px;
  margin-left: 10px;
  line-height: 50px;
  font-size: 16px;
  text-align: center;
  font-weight: 700;
}

.tobuy {
  font-weight: 400;
  font-size: 12px;
  font-family: none;
}
</style>